﻿#region Copyright(C) 2013-2013 NCS Pte. Ltd. All rights reserved.
// ==================================================================================================
// Copyright(C) 2010 NCS Pte. Ltd. All rights reserved.
//
// SYSTEM NAME      : iConnect .Net Application Framework
// COMPONENT ID     : NCS.IConnect.Core.EntLib
// COMPONENT DESC   : Microsoft Enterprise Library Adapter.
//
// CREATED DATE/BY  : 18 Dec 2013 / Jiang Jin Nan
//
// REVISION HISTORY :
// DATE/BY            SR#/CS/PM#/OTHERS       DESCRIPTION OF CHANGE
// ==================================================================================================
#endregion

using NCS.IConnect.Core.ExceptionHandling;
using NCS.IConnect.Core.IoC;
using System;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration;
using NCS.IConnect.Core.Utilities;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

namespace NCS.IConnect.Core.EntLib.ExceptionHandling
{
    [MapTo(typeof(IExceptionHandler), Lifetime = Lifetime.Singleton)]
    internal class DefaultExceptionHandler: IExceptionHandler
    {       
        public bool HandleException(Exception exceptionToHandle, string policyName, out Exception exceptionToThrow)
        {
            Guard.ArgumentNotNull(exceptionToHandle, "exceptionToHandle");
            Guard.ArgumentNotNullOrEmpty(policyName, "policyName");
            ExceptionHandlingSettings settings = ExceptionHandlingSettings.GetExceptionHandlingSettings(ConfigurationSourceFactory.Create());
            return settings.BuildExceptionManager().HandleException(exceptionToHandle, policyName, out exceptionToThrow);
        }
    }
}
